//
//  OneDetailCell.m
//  Kaoshiti
//
//  Created by lanou3g on 15/10/22.
//  Copyright (c) 2015年 张蒙恩. All rights reserved.
//

#import "OneDetailCell.h"

@interface OneDetailCell ()
@property (nonatomic ,strong)UIImageView *imageViewa;
@property (nonatomic ,strong)UILabel *titleLabel;
@property (nonatomic ,strong)UILabel *kidLabel;

@end

@implementation OneDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUpSubView];
    }
    return self;
}
- (void)setUpSubView
{
    self.imageViewa = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 100)];
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 10, 240, 60)];
    self.kidLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 75, 240, 30)];
    [self.contentView addSubview:self.imageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.kidLabel];
}

- (void)setOneDetailModel:(OneDetailModel *)oneDetailModel
{
    if (_oneDetailModel != oneDetailModel) {
        _oneDetailModel = nil;
        _oneDetailModel = oneDetailModel;
        [self layOutModel];
    }
}
- (void)layOutModel
{
    self.titleLabel.text = self.oneDetailModel.title;
    self.kidLabel.text = self.oneDetailModel.kid;
    self.titleLabel.numberOfLines = 0;
    self.kidLabel.numberOfLines = 0;

    
    CGFloat titleHeight= [[self class]heightForText:self.oneDetailModel.title width:240 FontSize:20];
    CGFloat kidHeight = [[self class]heightForText:self.oneDetailModel.kid width:240 FontSize:20];
    
    self.titleLabel.frame = CGRectMake(100, 10, 240, titleHeight);
    self.kidLabel.frame = CGRectMake(100, 20 + titleHeight, 240, kidHeight);
    UIImage *image = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:self.alltypeModel.imageName ofType:nil]];
    [self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
}

+ (CGFloat)heightForText:(NSString *)text width:(CGFloat)width FontSize:(NSInteger)fontSize
{
    CGSize size = CGSizeMake(width, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil];
    return rect.size.height;
}

+ (CGFloat)heigthForModel:(OneDetailModel *)model
{
    
    CGFloat titleHeight= [[self class]heightForText:model.title width:240 FontSize:20];
    CGFloat kidHeight = [[self class]heightForText:model.kid width:240 FontSize:20];
    
    
    return titleHeight + kidHeight + 25;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
